//
// Created by Administrator on 2021/8/15.
//

#ifndef STRUCTVIEW_STRINGVIEW_H
#define STRUCTVIEW_STRINGVIEW_H

#include "ViewInterface.h"
#include <cstring>

namespace details {
    class StringView : public ViewInterface {
    public:
        StringView(char* str, const char* _name, const char* _value) : data{str}, name{_name} {
            auto len = strlen(_value);
            char* value = new char[len + 1];
            strcpy_s(value, len, _value);
            value[len] = '\0';
        }

        auto build() -> void override{}
        auto equal() -> bool override{return true;}

        ~StringView() {
            delete []value;
        }

    private:
        char* data;
        const char* name;
        uint32_t len;
        char* value;
    };
}

#define __new_string_view__(param, str) new details::StringView(parent, TO_STRING(param), str)

#define __def_string_view__(param, str) \
[](auto&& parent) {                                      \
    return __new_string_view__(param, str); \
}(parent.param)

#define VString(param_name, str) __append_view__(__def_string_view__(param_name, str))

#endif //STRUCTVIEW_STRINGVIEW_H
